//
//  MeUserInfoCell.m
//  EFHealth
//
//  Created by nf on 16/8/5.
//  Copyright © 2016年 ef. All rights reserved.
//

#import "MeUserInfoCell.h"

static NSString *placeHolder = @"请输入您的昵称";

@interface MeUserInfoCell()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *arrorImg;
@property (nonatomic, nonnull,strong) UIImageView *iconImageView ;

@end

@implementation MeUserInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor whiteColor];
    // Initialization code
}
- (void)setTitle:(NSString *)title
{
    _title = title ;
    self.titleLabel.text = title ;
    if(ISEqual(title, @"手机号")){
        [self.arrorImg setHidden:YES];
    }
}
- (void)setSubTitle:(NSString *)subTitle
{
    _subTitle = subTitle ;
    self.subTitleLabel.text = subTitle ;
}
- (void)setUserIcon:(BOOL)userIcon
{
    _userIcon = userIcon ;
    
    if (userIcon) {
        self.iconImageView.hidden = NO ;
        _subTitleLabel.hidden = YES ;
        _textField.hidden = YES;
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:_subTitle] placeholderImage:kDefaultIconUser];
    }
    else{
        if (_iconImageView) {
            _iconImageView.hidden = YES ;
        }
    }
}
- (UIImageView *)iconImageView
{
    if (nil == _iconImageView) {
        _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-75, 8, 34, 34)];
//        _iconImageView.image = kDefaultIconUser ;
        [_iconImageView setCornerDefaultHalf];
        [self addSubview:_iconImageView];
    }
    return _iconImageView ;
}

- (UITextField *)textField
{
    if (nil == _textField) {
        _textField = [[UITextField alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-200, 0, 180, 50)];
        _textField.delegate = self;
        _textField.textColor = kTitleColor_light;
        _textField.font = kFontMidden;
        _textField.textAlignment = NSTextAlignmentRight;
        [self addSubview:_textField];
    }
    return _textField ;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (ISEqual(textField.text, placeHolder)){
        textField.text = @"";
        textField.textColor = kTitleColor_light;
    }else{
        textField.textColor = kTitleColor_midden;
    }
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.text.length == 0) {
        textField.text = placeHolder;
        textField.textColor = kTitleColor_light;
    }
}
@end
